<template>
	<view>
		<uni-nav-bar dark title="直播内容"  :statusBar="true" left-icon="left" @clickLeft="onLeft">

		</uni-nav-bar>
		
		<template>
			<uni-section title="拉流信息" type="line">
						<uni-list>
							<uni-list-item :title="playCode" >
								<template v-slot:footer>
									<button class="copyBtn" @click="onCopy">复制</button>
								</template>
							</uni-list-item>
							</uni-list>
					</uni-section>
			
			
			<uni-section title="推流地址" type="line">
				<uni-list>
					<uni-list-item :title="url" >
						<template v-slot:footer>
							<button class="copyBtn" @click="onStartCode">复制</button>
						</template>
					</uni-list-item>
				</uni-list>
			</uni-section>
			
			<view class="buttons">
				<button @click="onStart">开始直播</button>
			</view>
		</template>	
	</view>
</template>

<script>
	import {liverData} from '@/api/tournament/index.js'
	  import { getToken } from '@/utils/auth'
	  import {getseasonTournament} from '@/api/season/indx.js'
	  import {
	  	imageUrl
	  } from '@/config.js'
	export default {
		data() {
			return {
				url: '',
				id: '',
				time: '',
				info: {
					oneTeam: {},
					twoTeam: {}
				},
				imageUrl: imageUrl,
				playCode: ''
			}
		},
		methods: {
			onLeft() {
				uni.navigateBack()
			},
			onCopy() {
				uni.setClipboardData({
					data: this.playCode,
					success: function () {
						console.log('success');
						// this.$modal.msg('复制成功')
					}
				});
			},
			onStartCode() {
				uni.setClipboardData({
					data: this.url,
					success: function () {
						console.log('success');
					}
				});
			},
			onStart() {
				const liver = uni.requireNativePlugin('live-release-open');
				let leagueId = uni.getStorageSync('contestId');
				liver.startLive({
					title: ' ',
					token: getToken(),
					tournamentId: leagueId,
					dateTime: this.time,
					screenOrientation: 0
				}, sucess => {
					console.log(sucess)
				}) 
			}
		},
		onLoad({id, time}) {
			let leagueId = uni.getStorageSync('contestId');
			console.log(id,time,leagueId,"-----");
			this.id = leagueId;
			this.time = time;
			// getseasonTournament(leagueId).then(res => {
			// 	this.info = res.data;
			// })
			liverData({tournamentId: this.id,endTime: time,type:1}).then(res => {
				this.url = res.obsServer
				this.playCode = res.playCode
			})
		}
	}
</script>

<style scoped lang="scss">
	.copyBtn {
		background-color: $btn-bg-color;
		color: #fff;
		font-size: 24rpx;
	}
.buttons {
	margin-top: 40rpx;
	button {
		width: 90%;
		background-color: $btn-bg-color;
		color: #fff;
	}
}
</style>
